<template>
  <div class="app-container">
    <!-- 顶部控制台 -->
    <div class="filter-container">
      <el-input class="filter-item" style="width: 200px; margin-left: 0" size="mini" placeholder="请输入题目标题" v-model="form.searchTitle"/>
      <el-select class="filter-item" style="width: 160px" size="mini" v-model="form.searchStatus" @change="handlePageInit">
        <el-option v-for="item in pageData.searchStatusList" :key="item.value" :label="item.label" :value="item.value"/>
      </el-select>
      1
      <el-button size="mini" type="primary" icon="el-icon-search" @click="handlePageInit">搜索</el-button>
    </div>
    <!-- 页面数据列表 -->
    <div class="data-table">
      <el-table :data="responseData.tableList"
                border style="width: 100%;"
                v-loading="pageData.loading"
                element-loading-text="拼命加载中"
                element-loading-spinner="el-icon-loading"
                element-loading-background="rgba(0, 0, 0, 0.8)"
                :header-cell-style="{ background: '#545C64', color: '#ffffff' }"
                @selection-change="handleTableSelection">
        <el-table-column type="selection" width="55" align="center"/>
        <el-table-column fixed="left" prop="questionId" label="问答ID" width="280" align="center"></el-table-column>
        <el-table-column prop="questionQuestionerId" label="提问人ID" width="280" align="center"></el-table-column>
        <el-table-column prop="questionContent" label="提问内容" width="420" align="center"></el-table-column>
        <el-table-column prop="questionClickCount" label="点击量" width="80" align="center"></el-table-column>
        <el-table-column prop="questionCreateTime" label="提问时间" width="200" align="center"></el-table-column>
        <el-table-column label="是否向专家提问" width="120" align="center">
          <template slot-scope="scope">
            <span v-if="scope.row.questionIsAssignExpert === 0"><el-tag type="primary">普通问答</el-tag></span>
            <span v-if="scope.row.questionIsAssignExpert === 1"><el-tag type="warning">专家问答</el-tag></span>
            <span v-if="scope.row.questionIsAssignExpert === 2"><el-tag type="danger">悬赏问答</el-tag></span>
          </template>
        </el-table-column>
        <el-table-column fixed="right" label="操作" width="260" align="center">
          <template slot-scope="scope">
            <el-button type="primary" size="mini" @click="handleOpenCheckAnswerPage(scope)">查看回答</el-button>
            <el-button type="success" size="mini" @click="handleOpenSaveAnswerPage(scope)">回答</el-button>
            <el-button type="danger" size="small" @click="handleDeleteButtonClick(scope)">删除</el-button>
          </template>
        </el-table-column>
      </el-table>
    </div>
    <!-- 分页器 -->
    <div style="margin-top: 20px">
      <div class="block" style="width: 100%; text-align: center">
        <el-pagination
          layout="total, sizes, prev, pager, next, jumper"
          :current-page="form.pageNum"
          :page-size="form.pageSize"
          :total="form.total"
          :page-sizes="[12, 50, 100, 200]"
          @current-change="handleCurrentChange"
          @size-change="handleSizeChange">
        </el-pagination>
      </div>
    </div>
    <!-- 新增问题隐藏域 -->
    <div style="width: 60%; margin: auto">
      <el-dialog title="发布提问" :visible.sync="pageData.savePanelStatus" size="small"
                 :before-close="handleCloseSavePage">
        <div>
          <el-form ref="form" :model="form" label-width="120px">
            <el-form-item label="回答用户ID">
              <el-input v-model="form.questionQuestionerId" disabled></el-input>
            </el-form-item>
            <el-form-item label="问题标签">
              <el-checkbox-group v-model="pageData.questionLabel" size="mini" :min="1" :max="3">
                <el-checkbox-button v-for="label in responseData.questionLabel" :label="label.value" :key="label.value">{{label.label}}</el-checkbox-button>
              </el-checkbox-group>
            </el-form-item>
            <el-form-item label="提问内容">
              <el-input v-model="form.questionTitle" class="filter-item" auto-complete="off" type="textarea" :rows="6"/>
            </el-form-item>
            <el-form-item>
              <el-button type="primary" @click="handleSaveButtonClick">保存提问</el-button>
            </el-form-item>
          </el-form>
        </div>
      </el-dialog>
    </div>
    <!-- 查看回答隐藏域 -->
    <div style="width: 90%; margin: auto">
      <el-dialog title="回答列表" :visible.sync="pageData.checkAnswerStatus" size="small"
                 :before-close="handleCloseCheckAnswerPage">
        <el-table :data="responseData.questionAnswerList" border style="width: 100%">
          <el-table-column prop="answerContent" label="回答内容" width="320" align="center"></el-table-column>
          <el-table-column prop="questionAnswer" label="回答人" width="160" align="center"></el-table-column>
          <el-table-column label="是否后台回答" width="150" align="center">
            <template slot-scope="scope">
              <span v-if="scope.row.answerIsBack === 0"><el-tag type="warning">否</el-tag></span>
              <span v-if="scope.row.answerIsBack === 1"><el-tag type="success">是</el-tag></span>
            </template>
          </el-table-column>
          <el-table-column fixed="right" label="操作" width="180" align="center">
            <template slot-scope="scope">
              <el-button type="text" size="small" @click="handleOpenEditAnswerPage(scope)">修改回答</el-button>
              <el-button type="text" size="small" @click="handleDeleteAnswerButtonClick(scope)">删除回答</el-button>
            </template>
          </el-table-column>
        </el-table>
      </el-dialog>
    </div>
    <!-- 回答修改隐藏域 -->
    <div style="width: 60%; margin: auto">
      <el-dialog title="回答修改面板" :visible.sync="pageData.editAnswerStatus" size="small"
                 :before-close="handleCloseEditAnswerPage">
        <el-form ref="form" :model="form" label-width="120px">
          <el-form-item label="回答内容">
            <el-input v-model="form.answerContent" class="filter-item" auto-complete="off" type="textarea" :rows="8"/>
          </el-form-item>
          <el-form-item>
            <el-button type="primary" @click="handleEditAnswerButtonClick">保存回答数据</el-button>
          </el-form-item>
        </el-form>
      </el-dialog>
    </div>
    <!-- 回答问题隐藏域 -->
    <div style="width: 60%; margin: auto">
      <el-dialog title="问题回答" :visible.sync="pageData.saveAnswerStatus" size="small"
                 :before-close="handleCloseSaveAnswerPage">
        <div>
          <el-form ref="form" :model="form" label-width="120px">
            <el-form-item label="提问ID">
              <el-input v-model="form.questionId" disabled></el-input>
            </el-form-item>
            <el-form-item label="提问标题">
              <el-input v-model="form.questionTitle" disabled></el-input>
            </el-form-item>
            <el-form-item label="回答用户ID">
              <el-input v-model="form.answerUserId" disabled></el-input>
            </el-form-item>
            <el-form-item label="回答内容">
              <el-input v-model="form.answerContent" class="filter-item" auto-complete="off" type="textarea" :rows="8"/>
            </el-form-item>
            <el-form-item>
              <el-button type="primary" @click="handleSaveAnswerButtonClick">保存回答</el-button>
            </el-form-item>
          </el-form>
        </div>
      </el-dialog>
    </div>
  </div>
</template>

<script>
  // 组件引入
  import XLSX from 'xlsx';
  // 方法工具引入
  import { PermissionsToDetectFormUser } from '@/utils/PermissionsDetect';
  import { getPermission,getUserId } from '@/utils/UserCookies';
  // 接口引入
  import { loadCmsQuestionList,loadCmsQuestionLabelList,saveCmsQuestionData,loadCmsQuestionExpertList,loadCmsQuestionCountExpertList,
    loadCmsQuestionPayExpertList,loadCmsQuestionAnswerList,updateCmsQuestionAnswer,saveCmsAnswerData} from "@/api/question";
  export default {
    name: "expertPool",
    //import引入的组件需要注入到对象中才能使用
    components: {},
    data() {
      return {
        pageData:{
          loading: false,
          searchStatusList: [
            {label: "回答状态", value: -1},
            {label: "已回答", value: 1},
            {label: "未回答", value: 0},
          ],
          unlinkPanels: true,
          pickerOptions: {
            shortcuts: [{
              text: '最近一周',
              onClick(picker) {
                const end = new Date();
                const start = new Date();
                start.setTime(start.getTime() - 3600 * 1000 * 24 * 7);
                picker.$emit('pick', [start, end]);
              }
            }, {
              text: '最近一个月',
              onClick(picker) {
                const end = new Date();
                const start = new Date();
                start.setTime(start.getTime() - 3600 * 1000 * 24 * 30);
                picker.$emit('pick', [start, end]);
              }
            }, {
              text: '最近三个月',
              onClick(picker) {
                const end = new Date();
                const start = new Date();
                start.setTime(start.getTime() - 3600 * 1000 * 24 * 90);
                picker.$emit('pick', [start, end]);
              }
            }]
          },
          questionLabel: [],
          savePanelStatus: false,// 新增提问隐藏域
          checkAnswerStatus: false,// 查看回答隐藏域
          editAnswerStatus: false,// 修改回答隐藏域
          saveAnswerStatus: false,// 保存回答隐藏域
        },// 页面配置数据
        form:{
          searchTitle: "",
          searchStatus: -1,
          searchDate: "",
          startDate: "",
          endDate: "",
          searchAssignStatus: 1,
          pageNum: 1,// 表单--页码
          pageSize: 12,// 表单--页面
          total: 0,// 表单--总量
          selection: [],// 多选的内容
          // 新增提问
          questionQuestionerId: "",
          questionTitle: "",
          questionLabel: "",
          // 修改回答
          answerId: "",
          questionAnswerId: "",
          answerContent: "",
          // 保存回答
          questionId: "",
          answerUserId: "",
        },// 页面表单
        formRules: {},// 表单验证
        responseData: {
          tableList: [],
          questionLabel: [],
          expertQuestionList: [],
          expertQuestionCountList: [],
          expertQuestionPayList: [],
          questionAnswerList: [],
        },// 接口响应数据
      }
    },
    //监听属性 类似于data概念
    computed: {},
    //监控data中的数据变化
    watch: {},
    //方法集合
    methods:{
      // 事件函数
      handlePageInit(){
        this.form.pageNum = 1;
        this.pageData.loading = true;// 创建加载窗口
        this.loadCmsQuestionList();// 读取路由角色列表
        this.loadCmsQuestionLabelList();
      },// 页面初始化事件
      handleCurrentChange(val){
        this.form.pageNum = val;// 更换页码
        this.pageData.loading = true;// 创建加载窗口
        this.loadCmsQuestionList();// 读取路由角色列表
        this.loadCmsQuestionLabelList();
      },// 页码切换事件
      handleSizeChange(val){
        this.form.pageSize = val;// 更换页面大小
        this.pageData.loading = true;// 创建加载窗口
        this.loadCmsQuestionList();// 读取路由角色列表
        this.loadCmsQuestionLabelList();
      },// 页面size切换事件
      handleTableSelection(val){
        let list = [];// 初始化多选数组
        for (let i=0; i<val.length; i++){
          list.push(val[i].articleId);
        }// 遍历多选的列表，将ID拼入数组中
        this.form.selection = list;// 进行多选值的切换
      },// 表格多选事件
      handleOpenSavePage(){
        if (PermissionsToDetectFormUser(getPermission(), "470001")){
          this.form.questionQuestionerId = getUserId();
          this.pageData.savePanelStatus = true;
        } else {
          this.$message.warning('您的权限不足，无法使用此功能，请联系管理员');
        }
      },// 打开新增提问隐藏域
      handleCloseSavePage(){
        this.$confirm("确认关闭？").then(response => {
          this.form.questionQuestionerId = "";
          this.form.questionTitle = "";
          this.form.questionLabel = "";
          this.pageData.questionLabel = [];
          this.pageData.savePanelStatus = false;
        }).catch(err => {
          console.log(err);
        });
      },// 关闭新增提问隐藏域
      handleSaveButtonClick(){
        let re = /^[\u4E00-\u9FA5]$/;
        if (this.pageData.questionLabel.length === 0){
          this.$message.warning("请选择发布问题对应的标签");
          return;
        } else if (this.form.questionTitle === ""){
          this.$message.warning('不可发布无内容的提问数据，请填写相关信息');
          return;
        } else if (!re.test(this.form.questionTitle.substr(0,1))){
          this.$message.warning('发布的提问请以汉字开头');
          return;
        }
        if (PermissionsToDetectFormUser(getPermission(), "470001")){
          this.$confirm("是否保存当前数据?", "提示", {
            confirmButtonText: "确定",
            cancelButtonText: "取消",
            type: 'warning'
          }).then(() => {
            this.saveCmsQuestionData();
          }).catch(close => {
            console.log(close);
            this.$message.info("已取消操作");
          });
        } else {
          this.$message.warning("您的权限不足，无法使用此功能，请联系管理员");
        }
      },// 保存提问数据
      handleExportQuestionButtonClick(){
        if (PermissionsToDetectFormUser(getPermission(), "470004")){
          this.$confirm('确定导出当前问答数据？', '提示', {
            confirmButtonText: '确定',
            cancelButtonText: '取消',
            type: 'warning'
          }).then(() => {
            this.pageData.loading = true;// 创建加载窗口
            this.loadCmsQuestionExpertList();
          }).catch(close => {
            console.log(close);
            this.$message.info("已取消操作");
          });
        } else {
          this.$message.warning('您的权限不足，无法使用此功能，请联系管理员');
        }
      },// 导出问答数据
      handleExportQuestionCountButtonClick(){
        if (PermissionsToDetectFormUser(getPermission(), "470004")){
          this.$confirm('确定导出当前问答数据？', '提示', {
            confirmButtonText: '确定',
            cancelButtonText: '取消',
            type: 'warning'
          }).then(() => {
            this.pageData.loading = true;// 创建加载窗口
            this.loadCmsQuestionCountExpertList();
          }).catch(close => {
            console.log(close);
            this.$message.info("已取消操作");
          });
        } else {
          this.$message.warning('您的权限不足，无法使用此功能，请联系管理员');
        }
      },// 导出问答统计数据
      handleExportQuestionExpertButtonClick(){
        if (PermissionsToDetectFormUser(getPermission(), "470004")){
          this.$confirm('确定导出当前问答数据？', '提示', {
            confirmButtonText: '确定',
            cancelButtonText: '取消',
            type: 'warning'
          }).then(() => {
            this.pageData.loading = true;// 创建加载窗口
            this.loadCmsQuestionPayExpertList();
          }).catch(close => {
            console.log(close);
            this.$message.info("已取消操作");
          });
        } else {
          this.$message.warning('您的权限不足，无法使用此功能，请联系管理员');
        }
      },// 导出专家问答统计数据
      handleOpenCheckAnswerPage(scope){
        let param = {questionId: scope.row.questionId};
        this.loadCmsQuestionAnswerList(param);
      },// 打开查看回答面板
      handleCloseCheckAnswerPage(){
        this.$confirm("确认关闭？").then(response => {
          this.responseData.questionAnswerList = [];
          this.pageData.checkAnswerStatus = false;
        }).catch(err => {
          console.log(err);
        });
      },// 关闭查看回答的面板
      handleOpenEditAnswerPage(scope){
        if (PermissionsToDetectFormUser(getPermission(), "470003")){
          if (scope.row.questionAnswerId === getUserId()){
            // 关闭回答列表隐藏域
            this.responseData.questionAnswerList = [];
            this.pageData.checkAnswerStatus = false;
            // 打开回答修改隐藏域
            this.form.answerId = scope.row.answerId;
            this.form.questionAnswerId = scope.row.questionAnswerId;
            this.form.answerContent = scope.row.answerContent;
            this.pageData.editAnswerStatus = true;
          } else {
            this.$message.warning('抱歉，只能修改自己发布的回答');
          }
        } else {
          this.$message.warning('您的权限不足，无法使用此功能，请联系管理员');
        }
      },// 打开回答修改面板
      handleCloseEditAnswerPage(){
        this.$confirm("确认关闭？").then(response => {
          this.form.answerId = "";
          this.form.questionAnswerId = "";
          this.form.answerContent = "";
          this.pageData.editAnswerStatus = false;
        }).catch(err => {
          console.log(err);
        });
      },// 关闭回答修改面板
      handleEditAnswerButtonClick(){
        // 修改回答需先有修改回答的权限，并且要是自己回答的内容
        if (PermissionsToDetectFormUser(getPermission(), "470003")){
          if (this.form.questionAnswerId !== getUserId()){
            this.$message.warning('抱歉，只能修改自己发布的回答');
          } else {
            this.$confirm('你确定要修改这条回答内容？', '提示', {
              confirmButtonText: '确定',
              cancelButtonText: '取消',
              type: 'warning'
            }).then(() => {
              this.updateCmsQuestionAnswer();
            }).catch(close => {
              console.log(close);
              this.$message.info("已取消操作");
            });
          }
        } else {
          this.$message.warning('您的权限不足，无法使用此功能，请联系管理员');
        }
      },// 修改回答按钮
      handleDeleteAnswerButtonClick(scope){
        this.$message.info("该功能暂未开放，如有需要请联系管理员");
      },// 删除回答按钮点击事件
      handleOpenSaveAnswerPage(scope){
        if (PermissionsToDetectFormUser(getPermission(), "470001")){
          // 打开面板
          this.pageData.saveAnswerStatus = true;
          // 设置表单
          this.form.questionId = scope.row.questionId;
          this.form.questionTitle = scope.row.questionContent;
          this.form.answerUserId = getUserId();
          this.form.answerContent = "";
        } else {
          this.$message.warning('您的权限不足，无法使用此功能，请联系管理员');
        }
      },// 打开进行回答的面板
      handleCloseSaveAnswerPage(){
        this.$confirm("确认关闭？").then(response => {
          // 打开面板
          this.pageData.saveAnswerStatus = false;
          // 设置表单
          this.form.questionId = "";
          this.form.questionTitle = "";
          this.form.answerUserId = "";
          this.form.answerContent = "";
        }).catch(err => {
          console.log(err);
        });
      },// 关闭保存回答面板
      handleSaveAnswerButtonClick(){
        // 判断该用户是否有更改发布状态的权限
        if (PermissionsToDetectFormUser(getPermission(), "470001")){
          if (this.form.answerContent.length < 30){
            this.$notify({title: '请最少填写30字', type: 'info'});
          } else {
            this.$confirm('确定以此方式回答问题？', '提示', {
              confirmButtonText: '确定',
              cancelButtonText: '取消',
              type: 'warning'
            }).then(() => {
              this.saveCmsAnswerData();
            }).catch(close => {
              console.log(close);
              this.$message.info("已取消操作")
            });
          }
        } else {
          this.$message.warning('您的权限不足，无法使用此功能，请联系管理员');
        }
      },// 保存回答按钮点击事件
      handleDeleteButtonClick(){
        this.$message.info("该功能暂未开放，如有需要请联系管理员");
      },// 删除题目按钮点击事件
      // 接口
      loadCmsQuestionList(){
        let startData = "";
        let endData = "";
        if (this.form.searchDate !== null && this.form.searchDate !== ""){
          startData = new Date(this.form.searchDate[0]);
          startData = startData.getFullYear()+"-"+("0"+(startData.getMonth()+1)).slice(-2)+"-"+startData.getDate();
          endData = new Date(this.form.searchDate[1]);
          endData = endData.getFullYear()+"-"+("0"+(endData.getMonth()+1)).slice(-2)+"-"+endData.getDate();
          this.form.startDate = startData + " 00:00:00";
          this.form.endDate = endData + " 23:59:59";
        }
        loadCmsQuestionList(this.form).then(response => {
          if (response.code === "200"){
            this.pageData.loading = false;
            this.responseData.tableList = response.data.list;
            this.form.total = response.data.total;
          } else {
            this.$message.warning(response.message);
          }
        }).catch( error =>{
          console.log(error);
          this.$message.error(error);
        })
      },// 获取问答接口
      loadCmsQuestionLabelList(){
        loadCmsQuestionLabelList(this.form).then(response => {
          if (response.code === "200"){
            this.responseData.questionLabel = response.data;
          } else {
            this.$message.warning(response.message);
          }
        }).catch( error =>{
          console.log(error);
          this.$message.error(error);
        })
      },// 获取题目标签预设列表
      saveCmsQuestionData(){
        this.form.questionLabel = this.pageData.questionLabel.toString();
        saveCmsQuestionData(this.form).then(response => {
          if (response.code === "200"){
            this.form.questionQuestionerId = "";
            this.form.questionTitle = "";
            this.form.questionLabel = "";
            this.pageData.questionLabel = [];
            this.pageData.savePanelStatus = false;
            this.handlePageInit();
          } else {
            this.$message.warning(response.message);
          }
        }).catch( error =>{
          console.log(error);
          this.$message.error(error);
        })
      },// 保存提问数据
      loadCmsQuestionExpertList(){
        let startData = "";
        let endData = "";
        if (this.form.searchDate !== null && this.form.searchDate !== ""){
          startData = new Date(this.form.searchDate[0]);
          startData = startData.getFullYear()+"-"+("0"+(startData.getMonth()+1)).slice(-2)+"-"+startData.getDate();
          endData = new Date(this.form.searchDate[1]);
          endData = endData.getFullYear()+"-"+("0"+(endData.getMonth()+1)).slice(-2)+"-"+endData.getDate();
          this.form.startDate = startData + " 00:00:00";
          this.form.endDate = endData + " 23:59:59";
        }
        loadCmsQuestionExpertList(this.form).then(response => {
          if (response.code === "200"){
            this.responseData.expertQuestionList = response.data;
            // 导出数据统计表格
            let dataList = [];
            dataList.push(["提问人", "提问人手机号", "提问时间", "提问标题", "提问内容", "回答人", "回答人手机号", "回答时间", "回答内容"]);
            for (let i=0; i<this.responseData.expertQuestionList.length; i++){
              let data = [];
              data.push(this.responseData.expertQuestionList[i].questionUserName);
              data.push(this.responseData.expertQuestionList[i].questionUserPhone);
              data.push(this.responseData.expertQuestionList[i].questionCreateTime);
              data.push(this.responseData.expertQuestionList[i].questionTitle);
              data.push(this.responseData.expertQuestionList[i].questionContent);
              data.push(this.responseData.expertQuestionList[i].answerUserName);
              data.push(this.responseData.expertQuestionList[i].answerUserPhone);
              data.push(this.responseData.expertQuestionList[i].answerCreateTime);
              data.push(this.responseData.expertQuestionList[i].answerContent);
              dataList.push(data);
            }
            this.pageData.loading = false;
            setTimeout(function () {
              const ws = XLSX.utils.aoa_to_sheet(dataList);
              const wb = XLSX.utils.book_new();
              XLSX.utils.book_append_sheet(wb, ws, 'Sheet1');
              XLSX.writeFile(wb, "问答导出数据.xlsx");
            }, 800);
            this.handlePageInit();
          } else {
            this.$message.warning(response.message);
          }
        }).catch(error => {
          console.log(error);
          this.$message.error(error);
        })
      },// 导出问答数据
      loadCmsQuestionCountExpertList(){
        let startData = "";
        let endData = "";
        if (this.form.searchDate !== null && this.form.searchDate !== ""){
          startData = new Date(this.form.searchDate[0]);
          startData = startData.getFullYear()+"-"+("0"+(startData.getMonth()+1)).slice(-2)+"-"+startData.getDate();
          endData = new Date(this.form.searchDate[1]);
          endData = endData.getFullYear()+"-"+("0"+(endData.getMonth()+1)).slice(-2)+"-"+endData.getDate();
          this.form.startDate = startData + " 00:00:00";
          this.form.endDate = endData + " 23:59:59";
        }
        loadCmsQuestionCountExpertList(this.form).then(response => {
          if (response.code === "200"){
            this.responseData.expertQuestionCountList = response.data;
            // 导出数据统计表格
            let dataList = [];
            dataList.push(['提问统计人物ID', '提问统计人物手机号', '提问人物', '提问统计数量', '回答统计数量', '综合统计数量']);
            for (let i=0; i<this.responseData.expertQuestionCountList.length; i++){
              let data = [];
              data.push(this.responseData.expertQuestionCountList[i].questionUserId);
              data.push(this.responseData.expertQuestionCountList[i].questionAccount);
              data.push(this.responseData.expertQuestionCountList[i].questionUserName);
              data.push(this.responseData.expertQuestionCountList[i].questionCount);
              data.push(this.responseData.expertQuestionCountList[i].answerCount);
              data.push(this.responseData.expertQuestionCountList[i].comprehensiveUserCount);
              dataList.push(data);
            }
            this.pageData.loading = false;
            setTimeout(function () {
              const ws = XLSX.utils.aoa_to_sheet(dataList);
              const wb = XLSX.utils.book_new();
              XLSX.utils.book_append_sheet(wb, ws, 'Sheet1');
              XLSX.writeFile(wb, "问答统计导出数据.xlsx");
            }, 800);
            this.handlePageInit();
          } else {
            this.$message.warning(response.message);
          }
        }).catch(error => {
          console.log(error);
          this.$message.error(error);
        })
      },// 导出问答统计数据
      loadCmsQuestionPayExpertList(){
        let startData = "";
        let endData = "";
        if (this.form.searchDate !== null && this.form.searchDate !== ""){
          startData = new Date(this.form.searchDate[0]);
          startData = startData.getFullYear()+"-"+("0"+(startData.getMonth()+1)).slice(-2)+"-"+startData.getDate();
          endData = new Date(this.form.searchDate[1]);
          endData = endData.getFullYear()+"-"+("0"+(endData.getMonth()+1)).slice(-2)+"-"+endData.getDate();
          this.form.startDate = startData + " 00:00:00";
          this.form.endDate = endData + " 23:59:59";
        }
        loadCmsQuestionPayExpertList(this.form).then(response => {
          if (response.code === "200"){
            this.responseData.expertQuestionPayList = response.data;
            // 导出数据统计表格
            let dataList = [];
            dataList.push(['专家姓名', '收费单位', '答题数量']);
            for (let i=0; i<this.responseData.expertQuestionPayList.length; i++){
              let data = [];
              data.push(this.responseData.expertQuestionPayList[i].name);
              data.push(this.responseData.expertQuestionPayList[i].price);
              data.push(this.responseData.expertQuestionPayList[i].count);
              dataList.push(data);
            }
            this.pageData.loading = false;
            setTimeout(function () {
              const ws = XLSX.utils.aoa_to_sheet(dataList);
              const wb = XLSX.utils.book_new();
              XLSX.utils.book_append_sheet(wb, ws, 'Sheet1');
              XLSX.writeFile(wb, "专家问答统计导出数据.xlsx");
            }, 800);
            this.handlePageInit();
          } else {
            this.$message.warning(response.message);
          }
        }).catch(error => {
          console.log(error);
          this.$message.error(error);
        })
      },// 导出专家问答统计数据
      loadCmsQuestionAnswerList(param){
        loadCmsQuestionAnswerList(param).then(response => {
          if (response.code === "200"){
            this.pageData.checkAnswerStatus = true;
            this.responseData.questionAnswerList = response.data;
          } else {
            this.$message.warning(response.message);
          }
        }).catch( error =>{
          console.log(error);
          this.$message.error(error);
        })
      },// 获取回答列表数据
      updateCmsQuestionAnswer(){
        updateCmsQuestionAnswer(this.form).then(response => {
          if (response.code === "200"){
            this.$message.success("修改成功");
            this.form.answerId = "";
            this.form.questionAnswerId = "";
            this.form.answerContent = "";
            this.pageData.editAnswerStatus = false;
          } else {
            this.$message.warning(response.message);
          }
        }).catch( error =>{
          console.log(error);
          this.$message.error(error);
        })
      },// 修改回答数据
      saveCmsAnswerData(){
        saveCmsAnswerData(this.form).then(response => {
          if (response.code === "200"){
            this.$message.success("保存成功");
            // 打开面板
            this.pageData.saveAnswerStatus = false;
            // 设置表单
            this.form.questionId = "";
            this.form.questionTitle = "";
            this.form.answerUserId = "";
            this.form.answerContent = "";
            this.handlePageInit();
          } else {
            this.$message.warning(response.message);
          }
        }).catch( error =>{
          console.log(error);
          this.$message.error(error);
        })
      },// 保存回答数据
    },
    //生命周期 - 创建完成（可以访问当前this实例）
    created: function () {
      let _this = this;
      document.onkeydown = function(e) {
        if (!_this.pageData.loading) {
          let key = window.event.keyCode;
          if (key === 13) {
            _this.handlePageInit(); //此方法是当按下enter键后要做的动作。
          }
        }
      };
      // 进行初始化数据读取
      setTimeout(function () {
        _this.handlePageInit();
      }, 800);
    },
    //生命周期 - 挂载完成（可以访问DOM元素）
    mounted() {},
    beforeCreate() {}, //生命周期 - 创建之前
    beforeMount() {}, //生命周期 - 挂载之前
    beforeUpdate() {}, //生命周期 - 更新之前
    updated() {}, //生命周期 - 更新之后
    beforeDestroy() {}, //生命周期 - 销毁之前
    destroyed() {}, //生命周期 - 销毁完成
    activated() {}, //如果页面有keep-alive缓存功能，这个函数会触发
  };
</script>
<style rel="stylesheet/scss" lang="scss" scoped>
</style>
